﻿//====================================================================
// Create by Daniel
// file： YCModulePage.cs
// project ：YunCMS
// Build time：2012-09-18
// modify:
// description:
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using YunCMS.Model;
using YunCMS.IDAL;

namespace YunCMS.DAL
{
    /// <summary>
    /// Data Access Layer of dbo.YC_Module_Page.
    /// </summary>
    public partial class YCModulePageDAL : ModuleDAL<YCModulePage>, IYCModulePageDAL
    {
		#region 
		
		/// <summary>
		/// constractor
		/// </summary>
		public YCModulePageDAL()
		{
		}
		#endregion

        #region QueryString

        protected override string AddQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("insert into YC_Module_Page(");
                sqlStr.Append("CategoryID,Title,Keywords,Description,Author,IsHomePage,AddTime,UpdateTime,Access,Hits,IsPopular,ImageUrl,DiggTop,DiggStep,Active,Source,HtmlPageUrl,Lang,Content)");
                sqlStr.Append(" values (");
                sqlStr.Append("@CategoryID,@Title,@Keywords,@Description,@Author,@IsHomePage,getdate(),getdate(),@Access,@Hits,@IsPopular,@ImageUrl,@DiggTop,@DiggStep,@Active,@Source,@HtmlPageUrl,@Lang,@Content)");
                sqlStr.Append(";select @@IDENTITY");

                return sqlStr.ToString();
            }
        }

        protected override string UpdateQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("update YC_Module_Page set ");
                sqlStr.Append("CategoryID=@CategoryID,Title=@Title,Keywords=@Keywords,Description=@Description,Author=@Author,IsHomePage=@IsHomePage,UpdateTime=getdate(),Access=@Access,Hits=@Hits,IsPopular=@IsPopular,ImageUrl=@ImageUrl,DiggTop=@DiggTop,DiggStep=@DiggStep,Active=@Active,Source=@Source,HtmlPageUrl=@HtmlPageUrl,Lang=@Lang,Content=@Content");
                sqlStr.Append(" where ID=@ID");

                return sqlStr.ToString();
            }
        }
        #endregion

        #region -----------Methods-----------

        protected override string TableName
        {
            get { return "YC_Module_Page"; }
        }
		
        /// <summary>
		///Get YCModulePage Entity
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>YCModulePage Entity</returns>
        public override YCModulePage PopulateModelFromDr(IDataReader dr)
        {
            YCModulePage Obj = base.PopulateModelFromDr(dr);

            Obj.ImageUrl = dr["ImageUrl"].ToString();
            Obj.HtmlPageUrl = dr["HtmlPageUrl"].ToString();
            return Obj;
        }

        protected override List<SqlParameter> GetSelfParams(YCModulePage model)
        {
            List<SqlParameter> extParams = new List<SqlParameter>() {	
							new SqlParameter("@ImageUrl",SqlDbType.NVarChar),
							new SqlParameter("@HtmlPageUrl",SqlDbType.NVarChar)
			};

            if (model.ImageUrl != String.Empty)
                extParams[0].Value = model.ImageUrl;
            else
                extParams[0].Value = DBNull.Value;

            if (model.HtmlPageUrl != String.Empty)
                extParams[1].Value = model.HtmlPageUrl;
            else
                extParams[1].Value = DBNull.Value;		


            return extParams;
        }       
        
        #endregion
		
    }
}




